package com.mach.platform.service;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import com.google.common.collect.Maps;
import com.mach.platform.domain.Order;
import com.mach.platform.domain.OrderData;
import com.mach.platform.repository.OrderRepo;
import com.mach.platform.util.SqlHelper;
import com.mach.platform.utils.BeanChangeUtil;
import com.mach.platform.utils.OrderDict;
import com.mach.platform.utils.springdata.DynamicSpecifications;
import com.mach.platform.utils.springdata.SearchFilter;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.sql.DataSource;
import javax.transaction.Transactional;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import java.util.Random;

@Slf4j
@Service
public class OrderServiceImpl implements BaseService<Order>  {

    //已完成
    private static final Integer FINISHED = 1;
    //待处理
    private static final Integer PENDING = 2;
    //进行中
    private static final Integer ONGOING = 3;
    //完成的订单序号
    private static final Integer ORDER_SERIAL_NUMBER = null;
    //订单是否可操作 1:可操作 2:不可操作
    private static final Integer OPERATION_TRUE = 1;
    private static final Integer OPERATION_FALSE = 2;
    private static final String MOVEUP = "MoveUp";
    private static final String MOVEDOWN = "MoveDown";
    private static final DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    @Autowired
    private OrderRepo orderRepo;

    @Autowired
    private DataSource dataSource;

    @Autowired
    private OrderDataServiceImpl orderDataService;


    @Override
    public Order save(Order order) {
        order = this.initOrder(order);
        return orderRepo.saveAndFlush(order);
    }

    public Order initOrder(Order order){
        //状态为待处理
        order.setOrderStatus(PENDING);
        order.setClothSendingStatus(PENDING);
        order.setCoatingSectionStatus(PENDING);
        order.setCoilingSectionStatus(PENDING);

        //备料状态
        order.setBackupStatus(2);
        order.setSparePartsClothSendingStatus(2);
        order.setSparePartsCoatingSectionStatus(2);
        order.setSparePartsCoilingSectionStatus(2);
        //新插入的订单为可操作
        order.setOperation(OPERATION_TRUE);
        //录入时间
        order.setCreateOrderTime(LocalDateTime.now());
        return order;
    }

    @Override
    public List<Order> insertObjInBatch(List<Order> list) {
        return null;
    }

    @Override
    public Order update(Order order) {
        return orderRepo.saveAndFlush(order);
    }

    public int updateOrder(Order order) {
        return orderRepo.update(order);
    }

    @Transactional(rollbackOn = Exception.class)
    @Override
    public int delete(Long[] ids) {
        return orderRepo.deleteByIdIn(ids);
    }

    @Override
    public Page<Order> list(Pageable pageable, Map params) {

        if (params != null && params.size() > 0) {
            Object keyword = params.get("keyword");
            Object startTime = params.get("startTime");
            Object endTime = params.get("endTime");
            Object state = params.get("state");

            if (keyword != null && keyword != "") {
                params.put("customer_number_plike", keyword.toString().trim());
                params.remove("keyword");
            }
            if (startTime != null && startTime != "") {
                params.put("createOrderTime_gte", LocalDateTime.parse(startTime.toString().trim(), df));
                params.remove("startTime");
            }
            if (endTime != null && endTime != "") {
                params.put("createOrderTime_lte", LocalDateTime.parse(endTime.toString().trim(), df));
                params.remove("endTime");
            }
            if (state != null && state != "") {
                params.put("orderStatus_eq", Integer.parseInt(state.toString().trim()));
                params.remove("state");
            }

        }
//        Sort sort = new Sort(new Sort.Order(Sort.Direction.ASC, "serialNumber").nullsLast());
//        pageable.getSort().and(sort);
//        上面nullsLast貌似有bug
        Specification specification = DynamicSpecifications.bySearchFilter(SearchFilter.parse(params).values(), Order.class);
        Page<Order> result = orderRepo.findAll(specification, pageable);
        return result;
    }

    @Override
    public Order info(Long id) {
        return orderRepo.getById(id);
    }

    private List<Order> getAllSortBySerialNumber() {
        return orderRepo.findAll(new Sort(Sort.Direction.ASC,"operation","serialNumber"));
    }

    public Map<String, Object> getMain() {
        Map<String, Object> result = Maps.newHashMap();
        List<Order> orders = orderRepo.findAll();

        orders.forEach(item -> {
            if (item.getClothSendingStatus() != null && item.getClothSendingStatus() == ONGOING){
                //布发送
                result.put("clothSendingOrder", item);
                OrderData orderData = orderDataService.getDataByOrderId(item.getId());
                OrderData newOrderData = this.getPlcAndOrderData(orderData);
                result.put("clothSendingOrderData", newOrderData);
            }
            if (item.getCoatingSectionStatus() != null && item.getCoatingSectionStatus() == ONGOING){
                //涂布段
                result.put("coatingSectionOrder", item);
                OrderData orderData = orderDataService.getDataByOrderId(item.getId());
                OrderData newOrderData = this.getPlcAndOrderData(orderData);
                result.put("coatingSectionOrderData", newOrderData);
            }
            if (item.getCoilingSectionStatus() != null && item.getCoilingSectionStatus() == ONGOING){
                //卷取段
                result.put("coilingSectionOrder", item);
                OrderData orderData = orderDataService.getDataByOrderId(item.getId());
                OrderData newOrderData = this.getPlcAndOrderData(orderData);
                result.put("coilingSectionOrderData", newOrderData);
            }
        });

        return result;
    }

    private OrderData getPlcAndOrderData(OrderData orderData) {
        OrderData plcOrderData = this.getOrderData();
        BeanChangeUtil<T> beanChangeUtil = new BeanChangeUtil<>();
        OrderData newOrderData = (OrderData) beanChangeUtil.combineSydwCore(plcOrderData, orderData);
        return newOrderData;
    }


    /**
     * 获取未完成订单
     * @return
     */
    public List<Order> getOrderNotFinish(){
        return orderRepo.getOrderNotFinish();
    }

    public Order getOrderSerialNumber(Order order) {

        Integer maxSerialNumber = orderRepo.getOrderSerialNumber();
        if (maxSerialNumber == null){
            order.setSerialNumber(1);
        }else{
            order.setSerialNumber(maxSerialNumber + 1);
        }
        return order;
    }

    public String updateSerialNumber(Long id, String direction) {
        //获取订单
        Order exchangeOrder = orderRepo.getById(id);
        List<Order> orders = this.getAllSortBySerialNumber();
        //判断上移还是下移
        if (MOVEUP.equals(direction)){
            //上移 交换序号
            for (Order order : orders){
                if (order.getId() == exchangeOrder.getId()){
                    int index = orders.indexOf(order);
                    if (index != 0) {
                        return this.exchangeSerialNumber(exchangeOrder, orders.get(index - 1));
                    }
                }
            }
        }
        if (MOVEDOWN.equals(direction)){
            //下移 交换序号
            for (Order order : orders){
                if (order.getId() == exchangeOrder.getId()){
                    int index = orders.indexOf(order);
                    if (index != orders.size() - 1) {
                        return this.exchangeSerialNumber(exchangeOrder, orders.get(index + 1));
                    }
                }
            }
        }
        return "操作失败";
    }

    /**
     * 交换序号
     * @param order 需要交换序号的订单
     * @param item 被交换序号的订单
     */
    private String exchangeSerialNumber(Order order, Order item) {
        Integer temp = order.getSerialNumber();
        order.setSerialNumber(item.getSerialNumber());
        item.setSerialNumber(temp);
        //插入数据库
        this.update(order);
        this.update(item);
        return "操作成功";
    }


    /**
     * 开始作业或者停止作业(完成作业)
     * @param id 订单id
     * @param workName 作业阶段()
     * @param state 状态(start  finish)
     * @return
     */
    public String startOrFinishWork(Long id, String workName, String state) {
        final SqlHelper sqlHelper = SqlHelper.getBySource(dataSource);
        String sql = null;
        int intState = ONGOING;//3
        if (state.equals("finish")){
            intState = FINISHED;//1
        }
        Order order = orderRepo.getById(id);
        if (order == null){
            return "订单不存在";
        }
        //判断备料
        if (order.getSparePartsClothSendingStatus() == PENDING){
            return "布发送备料未准备完成";
        }
        if (order.getSparePartsCoatingSectionStatus() == PENDING){
            return "涂布段备料未准备完成";
        }
        if (order.getSparePartsCoilingSectionStatus() == PENDING){
            return "卷取段备料未准备完成";
        }
        switch (OrderWorkState.valueOf(workName)){
            //布发送
            case SENDING : {

                if (state.equals("start") && order.getClothSendingStatus() == ONGOING){
                    return "订单已经开始，请勿重复操作！";
                }
                if (state.equals("finish") && order.getClothSendingStatus() != ONGOING){
                    return "订单已完成或者还没开始，请确认";
                }
                sql = "update order_form set " + OrderWorkState.SENDING.getWorkState() + " = " + intState + " where id = " + id;
                //开始阶段,修改订单为进行中
                if (intState == ONGOING){
                    orderRepo.setOrderState(id, intState);
                }
                break;
            }
            //涂布段
            case COATING : {
                if (state.equals("start") && order.getCoatingSectionStatus() == ONGOING){
                    return "订单已经开始，请勿重复操作！";
                }
                if (state.equals("finish") && order.getCoatingSectionStatus() != ONGOING){
                    return "订单已完成或者还没开始，请确认";
                }
                sql = "update order_form set " + OrderWorkState.COATING.getWorkState() + " = " + intState + " where id = " + id;

                break;
            }
            //卷布段
            case COILING : {

                if (state.equals("start") && order.getCoilingSectionStatus() == ONGOING){
                    return "订单已经开始，请勿重复操作！";
                }
                if (state.equals("finish") && order.getCoilingSectionStatus() != ONGOING){
                    return "订单已完成或者还没开始，请确认";
                }
                sql = "update order_form set " + OrderWorkState.COILING.getWorkState() + " = " + intState + " where id = " + id;
                //最后阶段,修改订单为已完成
                if (intState == FINISHED){
                    //订单状态
                    orderRepo.setOrderState(id, intState);

                    //是否可操作
                    orderRepo.setOrderOperation(id, OPERATION_FALSE);
                }
                break;
            }
            default: {
                break;
            }
        }

        try {
            if (sql != null){
                sqlHelper.update(sql);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return "操作成功";
    }

    public Map<String, Object> getOrderByMainLeft() {
        List<Order> orders = this.getAllSortBySerialNumber();
        Map<String, Object> result;
        result = getCoatingSectionStatus(orders, ONGOING);
        if (result.size() == 0){
            result = getClothSendingStatus(orders, ONGOING);
        }
        return result;
    }

    public Map<String, Object> getClothSending() {
        List<Order> orders = this.getAllSortBySerialNumber();

        // 判断是否存在未完成订单，优先返回
        Map<String, Object> result = getClothSendingStatus(orders, ONGOING);
        if (result != null && result.size() > 0){
            return result;
        }
        return getClothSendingStatus(orders, PENDING);
    }

    public Map<String, Object> getCoatingSection() {
        List<Order> orders = this.getAllSortBySerialNumber();
        // 判断是否存在未完成订单，优先返回
        Map<String, Object> result = getCoatingSectionStatus(orders, ONGOING);
        if (result != null && result.size() > 0){
            return result;
        }
        return getCoatingSectionStatus(orders, PENDING);
    }

    public Map<String, Object> getCoilingSection() {
        List<Order> orders = this.getAllSortBySerialNumber();
        // 判断是否存在未完成订单，优先返回
        Map<String, Object> result = getCoilingSectionStatus(orders, ONGOING);
        if (result != null && result.size() > 0){
            return result;
        }
        return getCoilingSectionStatus(orders, PENDING);
    }

    /**
     * 获取布发送某个状态的当前订单和下一订单
     * @param orders
     * @param state
     * @return
     */
    public Map<String, Object> getClothSendingStatus(List<Order> orders, int state){
        Map<String, Object> result = Maps.newHashMap();
        for (Order order : orders){
            if (order.getClothSendingStatus() == state){
                result = getResultDataStage(order);
                result.put("nextOrder", "");
                if (orders.size() - 1 > orders.indexOf(order)){
                    Order nextOrder = orders.get(orders.indexOf(order) + 1);
                    if (nextOrder.getOrderStatus() != FINISHED) {
                        result.put("nextOrder", nextOrder);
                    }
                }
                break;
            }
        }
        return result;
    }

    /**
     * 获取涂布段某个状态的当前订单和下一订单
     * @param orders
     * @param state
     * @return
     */
    public Map<String, Object> getCoatingSectionStatus(List<Order> orders, int state){
        Map<String, Object> result = Maps.newHashMap();
        for (Order order : orders){
            if (order.getCoatingSectionStatus() == state){
                result = getResultDataStage(order);
                result.put("nextOrder", "");
                if (orders.size() - 1 > orders.indexOf(order)){
                    Order nextOrder = orders.get(orders.indexOf(order) + 1);
                    if (nextOrder.getOrderStatus() != FINISHED) {
                        result.put("nextOrder", nextOrder);
                    }
                }
                break;
            }
        }
        return result;
    }


    /**
     * 获取卷取段某个状态的当前订单和下一订单
     * @param orders
     * @param state
     * @return
     */
    public Map<String, Object> getCoilingSectionStatus(List<Order> orders, int state){
        Map<String, Object> result = Maps.newHashMap();
        for (Order order : orders){
            if (order.getCoilingSectionStatus() == state){
                result = getResultDataStage(order);
                result.put("nextOrder", "");
                if (orders.size() - 1 > orders.indexOf(order)){
                    Order nextOrder = orders.get(orders.indexOf(order) + 1);
                    if (nextOrder.getOrderStatus() != FINISHED) {
                        result.put("nextOrder", nextOrder);
                    }
                }
                break;
            }
        }
        return result;
    }

    public Map<String, Object> getResultDataStage(Order order){
        Map<String, Object> result = Maps.newHashMap();
        result.put("currentOrder", order);
        //获取实时plc数据
        OrderData orderData = getOrderData();
        //获取保存的数据
        OrderData saveOrderData = orderDataService.getDataByOrderId(order.getId());
        //合并两个实体
        BeanChangeUtil<T> beanChangeUtil = new BeanChangeUtil<>();
        OrderData newOrderData = (OrderData) beanChangeUtil.combineSydwCore(orderData, saveOrderData);

        result.put("currentOrderData", newOrderData);
        return result;
    }

    public OrderData getOrderData() {
        OrderData orderData = null;
        final SqlHelper sqlHelper = SqlHelper.getBySource(dataSource);
        String sql = "SELECT dev_id as devId, data_type as dataType, unit, dvalue, uptime from iot_dev_cur_data_win cur";
        try {
            List<Map<String,Object>> queryList = sqlHelper.queryList(sql);
            //通过反射设置字段值
            BeanChangeUtil<T> beanChangeUtil = new BeanChangeUtil<>();
            orderData = (OrderData) beanChangeUtil.setBeanValue(OrderData.class, OrderDict.fieldNameMaps, queryList);

        } catch (SQLException e) {
            e.printStackTrace();
        }
        return orderData;
    }




    /**
     * 获取岗位操作订单（未完成）
     * @param state 阶段
     * @return
     */
    public Map<String, Object> getJob(String state) {
        final SqlHelper sqlHelper = SqlHelper.getBySource(dataSource);
        String sql = null;
        switch (OrderWorkState.valueOf(state)){
            case SENDING : {
                sql = "select * from order_form where " + OrderWorkState.SENDING.getWorkState() + " = " + PENDING + " ORDER BY serial_number asc";
                break;
            }
            case COATING : {
                sql = "select * from order_form where " + OrderWorkState.COATING.getWorkState() + " = " + PENDING + " ORDER BY serial_number asc";
                break;
            }
            case COILING : {
                sql = "select * from order_form where " + OrderWorkState.COILING.getWorkState() + " = " + PENDING + " ORDER BY serial_number asc";
                break;
            }
            default: {
                break;
            }
        }
        if (sql != null) {
            List<Map<String, Object>> orderList = null;
            try {
                orderList = sqlHelper.queryList(sql);
            } catch (SQLException e) {
                e.printStackTrace();
            }
            if (orderList != null && orderList.size() > 0){
                return orderList.get(0);
            }
        }
        return null;
    }

    public String updateSparePartsById(Long id, int state, String workName) {
        final SqlHelper sqlHelper = SqlHelper.getBySource(dataSource);
        String sql = null;
        //判断是否已经开始
        Order order = orderRepo.getById(id);
        if (order == null){
            return "订单不存在";
        }
        if (state == FINISHED && order.getClothSendingStatus() == ONGOING){
            return "操作失败，订单已经开始";
        }
        //判断状态值
        if (state == FINISHED){
            state = PENDING;
        }else if (state == PENDING){
            state = FINISHED;
        }else{
            return "操作失败，状态传参错误";
        }

        switch (OrderWorkState.valueOf(workName)){
            case SPARE_PARTS_SENDING : {

                sql = "update order_form set "+ OrderWorkState.SPARE_PARTS_SENDING.getWorkState() +" = "+ state +" where id = " + id;
                break;
            }
            case SPARE_PARTS_COATING : {
                sql = "update order_form set "+ OrderWorkState.SPARE_PARTS_COATING.getWorkState() +" = "+ state +" where id = " + id;
                break;
            }
            case SPARE_PARTS_COILING : {
                sql = "update order_form set "+ OrderWorkState.SPARE_PARTS_COILING.getWorkState() +" = "+ state +" where id = " + id;
                break;
            }
            default: {
                break;
            }
        }
        int update = 0;
        if (sql != null){
            try {
                update = sqlHelper.update(sql);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return update == 1 ? "操作成功":"操作失败";
    }

    public synchronized String readExcelFile(MultipartFile file) throws Exception {
        if (file != null) {
            ImportParams params = new ImportParams();
            params.setHeadRows(1);
            List<Order> list = ExcelImportUtil.importExcel(
                    file.getInputStream(),Order.class, params);

            Integer serialNumber = orderRepo.getOrderSerialNumber();
            for (Order order : list){
                this.initOrder(order);
                serialNumber = ++serialNumber;
                order.setSerialNumber(serialNumber);
            }
            //TODO
            orderRepo.saveAll(list);
            return "导入成功";
        }
        return "导入失败";
    }

    public List<Order> setData(List<Order> orders){
        //模拟数据
        Random random = new Random();
        DecimalFormat df = new DecimalFormat("#.00");
        /*orders.forEach(item -> {
            int min = 41;
            int max = 43;
            item.setThreeMTroughTemperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setThreeMTroughTemperatureUnit("℃");
            min = 61;
            max = 65;
            item.setTemperatureSkinTemperatureFourHeatingWheels(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setTemperatureSkinTemperatureFourHeatingWheelsUnit("℃");
            min = 26;
            max = 30;
            item.setThirtyMTroughTemperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setThirtyMTroughTemperatureUnit("℃");
            min = 31;max = 35;
            item.setThirteenWashingTankTemperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setThirteenWashingTankTemperatureUnit("℃");
            item.setFourteenWashingTankTemperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setFourteenWashingTankTemperatureUnit("℃");
            item.setFifteenWashingTankTemperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setFifteenWashingTankTemperatureUnit("℃");
            item.setSixteenWashingTankTemperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setSixteenWashingTankTemperatureUnit("℃");
            item.setSeventeenWashingTankTemperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setSeventeenWashingTankTemperatureUnit("℃");
            min = 128;max = 132;
            item.setSkinTemperatureUpperLowerTenHeatingWheels1(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setSkinTemperatureUpperLowerTenHeatingWheels1Unit("℃");
            min =64;max=68;
            item.setSkinTemperatureUpperLowerTenHeatingWheels2(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setSkinTemperatureUpperLowerTenHeatingWheels2Unit("℃");
            min=98;max=102;
            item.setSkinTemperatureUpperLowerTenHeatingWheels3(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setSkinTemperatureUpperLowerTenHeatingWheels3Unit("℃");
            min=118;max=122;
            item.setSkinTemperatureUpperLowerTenHeatingWheels4(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setSkinTemperatureUpperLowerTenHeatingWheels4Unit("℃");
            min=128;max=132;
            item.setOven1Temperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOven1TemperatureUnit("℃");
            min=158;max=162;
            item.setOven2Temperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOven2TemperatureUnit("℃");
            item.setOven3Temperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOven3TemperatureUnit("℃");
            item.setOven4Temperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOven4TemperatureUnit("℃");
            item.setOven5Temperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOven5TemperatureUnit("℃");
            min=33;max=37;
            item.setOvenLeatherTemperature1(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOvenLeatherTemperature1Unit("℃");
            min=148;max=152;
            item.setOvenLeatherTemperature2(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOvenLeatherTemperature2Unit("℃");
            min=158;max=162;
            item.setOvenLeatherTemperature3(df.format(random.nextDouble() + random.nextInt(max - min) + min));
            item.setOvenLeatherTemperature3Unit("℃");
            min=148;max=152;
            item.setOvenLeatherTemperature4(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOvenLeatherTemperature4Unit("℃");
            min=152;max=157;
            item.setOvenLeatherTemperature5(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOvenLeatherTemperature5Unit("℃");
            min=93;max=97;
            item.setOvenLeatherTemperature6(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOvenLeatherTemperature6Unit("℃");
            min=78;max=79;
            item.setOvenLeatherTemperature7(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOvenLeatherTemperature7Unit("℃");
            min=12;max=13;
            item.setMainMotorCurrentOfOven(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setMainMotorCurrentOfOvenUnit("mA");
            min=8;max=9;
            item.setCurrent_1_1AirSupplyMotorLeft(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_1_1AirSupplyMotorLeftUnit("mA");
            item.setCurrent_1_1AirSupplyMotorRight(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_1_1AirSupplyMotorRightUnit("mA");
            item.setCurrent_1_2AirSupplyMotorLeft(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_1_2AirSupplyMotorLeftUnit("mA");
            item.setCurrent_1_2AirSupplyMotorRight(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_1_2AirSupplyMotorRightUnit("mA");
            item.setCurrent_2_1AirSupplyMotorLeft(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_2_1AirSupplyMotorLeftUnit("mA");
            item.setCurrent_2_1AirSupplyMotorRight(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_2_1AirSupplyMotorRightUnit("mA");
            item.setCurrent_2_2AirSupplyMotorLeft(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_2_2AirSupplyMotorLeftUnit("mA");
            item.setCurrent_2_2AirSupplyMotorRight(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_2_2AirSupplyMotorRightUnit("mA");
            min=3;max=4;
            item.setCurrent_3_1AirSupplyMotorLeft(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_3_1AirSupplyMotorLeftUnit("mA");
            min=8;max=9;
            item.setCurrent_3_1AirSupplyMotorRight(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_3_1AirSupplyMotorRightUnit("mA");
            item.setCurrent_3_2AirSupplyMotorLeft(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_3_2AirSupplyMotorLeftUnit("mA");
            item.setCurrent_3_2AirSupplyMotorRight(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_3_2AirSupplyMotorRightUnit("mA");
            item.setCurrent_4_1AirSupplyMotorLeft(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_4_1AirSupplyMotorLeftUnit("mA");
            item.setCurrent_4_1AirSupplyMotorRight(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_4_1AirSupplyMotorRightUnit("mA");
            item.setCurrent_4_2AirSupplyMotorLeft(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_4_2AirSupplyMotorLeftUnit("mA");
            item.setCurrent_4_2AirSupplyMotorRight(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_4_2AirSupplyMotorRightUnit("mA");
            item.setCurrent_5_1AirSupplyMotorLeft(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_5_1AirSupplyMotorLeftUnit("mA");
            item.setCurrent_5_1AirSupplyMotorRight(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_5_1AirSupplyMotorRightUnit("mA");
            item.setCurrent_5_2AirSupplyMotorLeft(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_5_2AirSupplyMotorLeftUnit("mA");
            item.setCurrent_5_2AirSupplyMotorRight(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_5_2AirSupplyMotorRightUnit("mA");
            min=48;max=49;
            item.setOneOutdoorExhaustWindmillCurrent(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOneOutdoorExhaustWindmillCurrentUnit("mA");
            min=38;max=39;
            item.setOneOutdoorExhaustWindmillTemperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOneOutdoorExhaustWindmillTemperatureUnit("mA");
            min=105;max=110;
            item.setOneOutdoorExhaustWindmillCurrent(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOneOutdoorExhaustWindmillCurrentUnit("℃");
            min=30;max=34;
            item.setTwoOutdoorExhaustWindmillTemperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setTwoOutdoorExhaustWindmillTemperatureUnit("℃");
        });*/
        return orders;
    }

    public OrderData setData(OrderData item) {
        //模拟数据
        Random random = new Random();
        DecimalFormat df = new DecimalFormat("#.00");
            int min = 41;
            int max = 43;
            item.setThreeMTroughTemperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setThreeMTroughTemperatureUnit("℃");
            min = 61;
            max = 65;
            item.setTemperatureSkinTemperatureFourHeatingWheels(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setTemperatureSkinTemperatureFourHeatingWheelsUnit("℃");
            min = 26;
            max = 30;
            item.setThirtyMTroughTemperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setThirtyMTroughTemperatureUnit("℃");
            min = 31;max = 35;
            item.setThirteenWashingTankTemperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setThirteenWashingTankTemperatureUnit("℃");
            item.setFourteenWashingTankTemperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setFourteenWashingTankTemperatureUnit("℃");
            item.setFifteenWashingTankTemperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setFifteenWashingTankTemperatureUnit("℃");
            item.setSixteenWashingTankTemperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setSixteenWashingTankTemperatureUnit("℃");
            item.setSeventeenWashingTankTemperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setSeventeenWashingTankTemperatureUnit("℃");
            min = 128;max = 132;
            item.setSkinTemperatureUpperLowerTenHeatingWheels1(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setSkinTemperatureUpperLowerTenHeatingWheels1Unit("℃");
            min =64;max=68;
            item.setSkinTemperatureUpperLowerTenHeatingWheels2(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setSkinTemperatureUpperLowerTenHeatingWheels2Unit("℃");
            min=98;max=102;
            item.setSkinTemperatureUpperLowerTenHeatingWheels3(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setSkinTemperatureUpperLowerTenHeatingWheels3Unit("℃");
            min=118;max=122;
            item.setSkinTemperatureUpperLowerTenHeatingWheels4(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setSkinTemperatureUpperLowerTenHeatingWheels4Unit("℃");
            min=128;max=132;
            item.setOven1Temperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOven1TemperatureUnit("℃");
            min=158;max=162;
            item.setOven2Temperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOven2TemperatureUnit("℃");
            item.setOven3Temperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOven3TemperatureUnit("℃");
            item.setOven4Temperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOven4TemperatureUnit("℃");
            item.setOven5Temperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOven5TemperatureUnit("℃");
            min=33;max=37;
            item.setOvenLeatherTemperature1(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOvenLeatherTemperature1Unit("℃");
            min=148;max=152;
            item.setOvenLeatherTemperature2(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOvenLeatherTemperature2Unit("℃");
            min=158;max=162;
            item.setOvenLeatherTemperature3(df.format(random.nextDouble() + random.nextInt(max - min) + min));
            item.setOvenLeatherTemperature3Unit("℃");
            min=148;max=152;
            item.setOvenLeatherTemperature4(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOvenLeatherTemperature4Unit("℃");
            min=152;max=157;
            item.setOvenLeatherTemperature5(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOvenLeatherTemperature5Unit("℃");
            min=93;max=97;
            item.setOvenLeatherTemperature6(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOvenLeatherTemperature6Unit("℃");
            min=78;max=79;
            item.setOvenLeatherTemperature7(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOvenLeatherTemperature7Unit("℃");
            min=12;max=13;
            item.setMainMotorCurrentOfOven(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setMainMotorCurrentOfOvenUnit("mA");
            min=8;max=9;
            item.setCurrent_1_1AirSupplyMotorLeft(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_1_1AirSupplyMotorLeftUnit("mA");
            item.setCurrent_1_1AirSupplyMotorRight(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_1_1AirSupplyMotorRightUnit("mA");
            item.setCurrent_1_2AirSupplyMotorLeft(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_1_2AirSupplyMotorLeftUnit("mA");
            item.setCurrent_1_2AirSupplyMotorRight(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_1_2AirSupplyMotorRightUnit("mA");
            item.setCurrent_2_1AirSupplyMotorLeft(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_2_1AirSupplyMotorLeftUnit("mA");
            item.setCurrent_2_1AirSupplyMotorRight(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_2_1AirSupplyMotorRightUnit("mA");
            item.setCurrent_2_2AirSupplyMotorLeft(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_2_2AirSupplyMotorLeftUnit("mA");
            item.setCurrent_2_2AirSupplyMotorRight(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_2_2AirSupplyMotorRightUnit("mA");
            min=3;max=4;
            item.setCurrent_3_1AirSupplyMotorLeft(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_3_1AirSupplyMotorLeftUnit("mA");
            min=8;max=9;
            item.setCurrent_3_1AirSupplyMotorRight(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_3_1AirSupplyMotorRightUnit("mA");
            item.setCurrent_3_2AirSupplyMotorLeft(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_3_2AirSupplyMotorLeftUnit("mA");
            item.setCurrent_3_2AirSupplyMotorRight(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_3_2AirSupplyMotorRightUnit("mA");
            item.setCurrent_4_1AirSupplyMotorLeft(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_4_1AirSupplyMotorLeftUnit("mA");
            item.setCurrent_4_1AirSupplyMotorRight(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_4_1AirSupplyMotorRightUnit("mA");
            item.setCurrent_4_2AirSupplyMotorLeft(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_4_2AirSupplyMotorLeftUnit("mA");
            item.setCurrent_4_2AirSupplyMotorRight(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_4_2AirSupplyMotorRightUnit("mA");
            item.setCurrent_5_1AirSupplyMotorLeft(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_5_1AirSupplyMotorLeftUnit("mA");
            item.setCurrent_5_1AirSupplyMotorRight(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_5_1AirSupplyMotorRightUnit("mA");
            item.setCurrent_5_2AirSupplyMotorLeft(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_5_2AirSupplyMotorLeftUnit("mA");
            item.setCurrent_5_2AirSupplyMotorRight(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setCurrent_5_2AirSupplyMotorRightUnit("mA");
            min=48;max=49;
            item.setOneOutdoorExhaustWindmillCurrent(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOneOutdoorExhaustWindmillCurrentUnit("mA");
            min=38;max=39;
            item.setOneOutdoorExhaustWindmillTemperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOneOutdoorExhaustWindmillTemperatureUnit("mA");
            min=105;max=110;
            item.setOneOutdoorExhaustWindmillCurrent(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setOneOutdoorExhaustWindmillCurrentUnit("℃");
            min=30;max=34;
            item.setTwoOutdoorExhaustWindmillTemperature(df.format(random.nextDouble() + random.nextInt(max-min)+min));
            item.setTwoOutdoorExhaustWindmillTemperatureUnit("℃");
        return item;
    }

}
